package com.eling.elcms.travel.service;

import com.eling.elcms.core.AppContext;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.ordermanager.model.Attendant;
import com.eling.elcms.ordermanager.service.IAttendantManager;
import com.eling.elcms.system.model.CommonUser;
import com.eling.elcms.system.service.ICommonUserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrgUsersApprovalRule implements IApprovalRule{
	@Autowired
	private IAttendantManager attendantManager;
	@Autowired
	private ICommonUserManager commonUserManager;
	
	@Override
	public Map<String, String> candidatePara() {
		Map<String, String> map = new HashMap<>();
		CommonUser cu = (CommonUser)AppContext.curUser();
		Attendant cond = new Attendant();
		cond.setOrganization(cu.getOrganization());
		List<Attendant> list = attendantManager.query(cond);
		for (Attendant att : list) {
			map.put(att.getCommonUser().getPkUser().toString(), att.getCommonUser().getName());
		}
		return map;
	}

	@Override
	public CommonUser getApproval(String para, BaseModel model) {
		return commonUserManager.get(Long.valueOf(para));
	}
}
